import {Component, Input, OnInit} from '@angular/core';


@Component({
  selector: 'app-image-picker',
  templateUrl: './image-picker.component.html',
  styleUrls: ['./image-picker.component.scss']
})
export class ImagePickerComponent implements OnInit {

  @Input() type = 'file'; // default

  fileUrl;

  constructor() { }

  ngOnInit() {
  }

  onChange(event): void {
    if(event.target.files && event.target.files[0]) {
      let reader = new FileReader();

      reader.onload = (e:any) => {
        this.fileUrl = e.target.result;
      };

      reader.readAsDataURL(event.target.files[0]);
    }
  }

}
